home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1995 April / Internet Tools.iso / applic / ncsa / Mac / Telnet2.6 / prerelease / d5 / Telnet 2.6.1d5.src.sit.hqx / Telnet 2.6.1d5 src / source / main / Connections.c oldauth next >
Encoding:
Text File  |  1994-06-21  |  19.6 KB  |  652 lines

  1. /****************************************************************
  2. *    NCSA Telnet for the Macintosh                                *
  3. *                                                                *
  4. *    National Center for Supercomputing Applications                *
  5. *    Software Development Group                                    *
  6. *    152 Computing Applications Building                            *
  7. *    605 E. Springfield Ave.                                        *
  8. *    Champaign, IL  61820                                        *
  9. *                                                                *
  10. *    Copyright (c) 1986-1993,                                    *
  11. *    Board of Trustees of the University of Illinois                *
  12. *****************************************************************/
  13.  
  14. #ifdef MPW
  15. #pragma segment 4
  16. #endif
  17.  
  18. #include <stdio.h>
  19. #include <string.h>
  20. #include <stdlib.h>
  21.  
  22. #include "TelnetHeader.h"
  23.  
  24. #include "telneterrors.h"
  25. #include "DlogUtils.proto.h"
  26.  
  27. #include "wind.h"
  28. #include "event.proto.h"
  29.  
  30. #include "rsmac.proto.h"
  31. #include "vsdata.h"
  32. #include "vskeys.h"
  33. #include "vsinterf.proto.h"
  34. #include "vgtek.proto.h"
  35. #include "tekrgmac.proto.h"
  36. #include "vr.h"
  37. #include "vrrgmac.proto.h" 
  38. #include "network.proto.h"
  39. #include "mydnr.proto.h"
  40. #include "InternalEvents.h"
  41. #include "menuseg.proto.h"
  42. #include "maclook.proto.h"
  43. #include "parse.proto.h"
  44. #include "parse.h"
  45. #include "configure.proto.h"
  46.  
  47. #include "prefs.proto.h"
  48. #include "popup.h"
  49. #include "popup.proto.h"
  50.  
  51. #include "Connections.proto.h"
  52. #ifdef newauth                            /* (RW) */
  53. #include "tnae.h"
  54. #include "authencrypt.h"
  55. #include "authencrypt.proto.h"
  56. #else
  57. #include "encrypt.proto.h"
  58. #endif
  59. #include "wdefpatch.proto.h"
  60.  
  61. /*    These are all of the variables we need... */
  62.  
  63. extern    Cursor    *theCursors[NUMCURS];        /* all the cursors in a nice bundle */
  64. extern    WindRec    *screens;
  65. extern    short    scrn;
  66. extern    short    nNational;                // Number of user-installed translation tables
  67. extern    MenuHandle    myMenus[];
  68. extern    Boolean    authOK;
  69. extern    Boolean    encryptOK;
  70.  
  71. static    pascal short POCdlogfilter( DialogPtr dptr, EventRecord *evt, short *item);
  72. PROTO_UPP(POCdlogfilter, ModalFilter);
  73.  
  74. void OpenPortSpecial(MenuHandle menuh, short item)
  75. {
  76.     ConnInitParams        **theParams;
  77.     Boolean                success;
  78.     Str255                scratchPstring;
  79.     
  80.     GetItem(menuh, item, scratchPstring);
  81.     
  82.     theParams = NameToConnInitParams(scratchPstring);
  83.     if (theParams == NULL) {
  84.         OutOfMemory(1020);
  85.         return;
  86.         }
  87.         
  88.     success = CreateConnectionFromParams(theParams);
  89. }
  90.  
  91. SIMPLE_UPP(POCdlogfilter, ModalFilter);
  92. pascal short POCdlogfilter( DialogPtr dptr, EventRecord *evt, short *item)
  93. {
  94.     short key;
  95.  
  96.     if (evt->what == keyDown) {
  97.         key = evt->message & charCodeMask;
  98.         if ( ((key == 'F') || (key == 'f')) && (evt->modifiers & cmdKey) ) {
  99.             *item = NCftpcheckbox;
  100.             return(-1);
  101.             }
  102.         if ( ((key == 'A') || (key == 'a')) && (evt->modifiers & cmdKey) ) {
  103.             *item = NCauthenticate;
  104.             return(-1);
  105.             }
  106.         if ( ((key == 'E') || (key == 'e')) && (evt->modifiers & cmdKey) ) {
  107.             *item = NCencrypt;
  108.             return(-1);
  109.             }
  110.         }
  111.     
  112.     return(DLOGwOK_Cancel(dptr, evt, item));
  113. }
  114.  
  115. void    PresentOpenConnectionDialog(void)
  116. {
  117.     ConnInitParams    **InitParams;
  118.     DialogPtr        dptr;
  119.     short            ditem, scratchshort;
  120.     static long        numWind = 1;
  121.     Boolean            success;
  122.     long            scratchlong;
  123.     Str255            scratchPstring;
  124.     Handle            ItemHandle;
  125.     SessionPrefs    **defaultSessHdl;
  126.     MenuHandle        SessPopupHdl;
  127.     Rect            scratchRect;
  128.     Point            SessPopupLoc;
  129.     
  130.     SetCursor(theCursors[normcurs]);
  131.     
  132.     dptr = GetNewMyDialog(NewCnxnDLOG, NULL, kInFront, (void *)ThirdCenterDialog);
  133.     if (dptr == NULL) {
  134.         OutOfMemory(1000);
  135.         return;
  136.         }
  137.         
  138.     ditem = 3;
  139.     
  140.     SessPopupHdl = NewMenu(668, "\pSession:");
  141.     if (SessPopupHdl == NULL) {
  142.         OutOfMemory(1000);
  143.         DisposeDialog(dptr);
  144.         return;
  145.         }
  146.         
  147.     UseResFile(TelInfo->SettingsFile);
  148.     AddResMenu(SessPopupHdl, SESSIONPREFS_RESTYPE);
  149.     EnableItem(SessPopupHdl, 0);        // Make sure the entire menu is enabled
  150.     
  151.     GetDItem(dptr, NCsesspopup, &scratchshort, &ItemHandle, &scratchRect);
  152.     SessPopupLoc.h = scratchRect.left;
  153.     SessPopupLoc.v = scratchRect.top;
  154.     SetPort(dptr);
  155.     LocalToGlobal(&SessPopupLoc);
  156.     
  157.     // Get default auth/encrypt settings from default session
  158.     defaultSessHdl = GetDefaultSession();
  159.     HLock((Handle)defaultSessHdl);
  160.  
  161.     BlockMove("\p<Default>", scratchPstring, 15);
  162.     GetHostNameFromSession(scratchPstring);
  163.     SetTEText(dptr, NChostname, scratchPstring);
  164.     SelIText(dptr, NChostname, 0, 32767);
  165.  
  166.     SetCntrl(dptr, NCauthenticate, (**defaultSessHdl).authenticate && authOK);
  167.     SetCntrl(dptr, NCencrypt, (**defaultSessHdl).encrypt && encryptOK);
  168.     DisposeHandle((Handle)defaultSessHdl);
  169.         
  170.     setSessStates(dptr);
  171.  
  172.     while (ditem > NCcancel) {
  173.         ModalDialog(POCdlogfilterUPP, &ditem);
  174.         switch(ditem) {
  175.             case    NCftpcheckbox:
  176.             case    NCauthenticate:
  177.             case    NCencrypt:
  178.                 GetDItem(dptr, ditem, &scratchshort, &ItemHandle, &scratchRect);
  179.                 if ((**(ControlHandle)ItemHandle).contrlHilite == 0) {    // if control not disabled
  180.                     FlipCheckBox(dptr, ditem);
  181.                     setSessStates(dptr);
  182.                 }
  183.                 break;
  184.  
  185.             case    NCsesspopup:
  186.                 InsertMenu(SessPopupHdl, hierMenu);
  187.                 CalcMenuSize(SessPopupHdl);
  188.                 scratchlong = PopUpMenuSelect(SessPopupHdl, SessPopupLoc.v,
  189.                                                 SessPopupLoc.h, 0);
  190.                 DeleteMenu(668);
  191.                 if (scratchlong) {
  192.                     scratchshort = scratchlong & 0xFFFF; //    Apple sez ignore the high word
  193.                     GetItem(SessPopupHdl, scratchshort, scratchPstring);
  194.                     SetTEText(dptr, NChostname, scratchPstring);
  195.                     SelIText(dptr, NChostname, 0, 32767);
  196.                     }
  197.                 break;
  198.                                 
  199.             default:
  200.                 break;
  201.             } // switch
  202.         } // while
  203.     
  204.     DisposeMenu(SessPopupHdl);
  205.     
  206.     if (ditem == NCcancel) {
  207.         DisposeDialog(dptr);
  208.         return;
  209.         }
  210.     
  211.     GetTEText(dptr, NChostname, scratchPstring);
  212.     if (!Length(scratchPstring)) {
  213.         DisposeDialog(dptr);
  214.         return;
  215.         }
  216.         
  217.     InitParams = NameToConnInitParams(scratchPstring);
  218.     if (InitParams == NULL) {
  219.         OutOfMemory(1000);
  220.         DisposeDialog(dptr);
  221.         return;
  222.         }
  223.  
  224.     HLock((Handle)InitParams);
  225.     HLock((Handle)(**InitParams).session);
  226.     GetTEText(dptr, NCwindowname, scratchPstring);
  227.  
  228.     // Copy over the user specified window name.  If blank, CreateConnectionFromParams 
  229.     // will copy the hostname to the windowname and append a number.
  230.     if (Length(scratchPstring)) 
  231.         BlockMove(scratchPstring, (**InitParams).WindowName,
  232.                     (Length(scratchPstring) > 63) ? 64 : (Length(scratchPstring) + 1));
  233.  
  234.     if (GetCntlVal(dptr, NCftpcheckbox)) {
  235.         (**InitParams).ftpstate = 1;
  236.         (**(**InitParams).session).halfdup = 1;        /* BYU */
  237.         }
  238.      if (GetCntlVal(dptr, NCauthenticate))
  239.           (**(**InitParams).session).authenticate = 1;
  240.      else
  241.          (**(**InitParams).session).authenticate = 0;
  242.      if (GetCntlVal(dptr, NCencrypt))
  243.           (**(**InitParams).session).encrypt = 1;
  244.      else
  245.          (**(**InitParams).session).encrypt = 0;
  246.         
  247.     HUnlock((Handle)(**InitParams).session);
  248.     HUnlock((Handle)InitParams);
  249.         
  250.     DisposeDialog(dptr);
  251.     
  252.     success = CreateConnectionFromParams(InitParams);
  253. }
  254.  
  255. // Set states of session checkboxes
  256. void setSessStates (DialogPtr dptr)
  257. {
  258.     if (GetCntlVal(dptr, NCftpcheckbox)  || !authOK)
  259.         Hilite(dptr, NCauthenticate, 255);
  260.     else
  261.         Hilite(dptr, NCauthenticate, 0);
  262.         
  263.     if (GetCntlVal(dptr, NCauthenticate)) {
  264.         Hilite(dptr, NCftpcheckbox, 255);
  265.         Hilite(dptr, NCencrypt, (encryptOK)? 0 : 255);
  266.     } else {
  267.         Hilite(dptr, NCftpcheckbox, 0);
  268.         Hilite(dptr, NCencrypt, 255);
  269.         SetCntrl(dptr, NCencrypt, false);
  270.     }
  271. }
  272.         
  273. Boolean CreateConnectionFromParams( ConnInitParams **Params)
  274. {
  275.     short            scratchshort, fontnumber, offset;
  276.     static short    numWind = 1, stagNum = 1;
  277.     SessionPrefs    *SessPtr;
  278.     TerminalPrefs    *TermPtr;
  279.     short            cur;
  280.     Str32            numPstring;
  281.     Str255            scratchPstring;
  282.     Boolean            scratchBoolean;
  283.     
  284.     SetCursor(theCursors[watchcurs]);                    /* We may be here a bit */
  285.  
  286.     // Check if we have the max number of sessions open
  287.     if (TelInfo->numwindows == MaxSess) return(FALSE);
  288.     
  289.     cur = TelInfo->numwindows;            /* Adjust # of windows and get this window's number */
  290.     TelInfo->numwindows++;
  291.     screens[cur].active = CNXN_NOTINUSE;    // Make sure it is marked as dead (in case we
  292.                                         // abort screen creation after initiating DNR.
  293.                                         // That way CompleteConnectionOpening will know
  294.                                         // we didn't make it.
  295.     HLockHi((Handle)Params);
  296.     HLockHi((Handle)(**Params).terminal);
  297.     HLockHi((Handle)(**Params).session);
  298.     SessPtr = *((**Params).session);
  299.     TermPtr = *((**Params).terminal);
  300.  
  301.     if (Length((**Params).WindowName) == 0) {
  302.         BlockMove((**(**Params).session).hostname, (**Params).WindowName, 
  303.                     Length((**(**Params).session).hostname)+1);
  304.         NumToString(numWind++, numPstring);
  305.         pstrcat((**Params).WindowName, "\p ");
  306.         pstrcat((**Params).WindowName, numPstring);    // tack the number onto the end.
  307.         }
  308.         
  309.     // Get the IP for the host while we set up the connection
  310.     if (DoTheDNR(SessPtr->hostname, cur) != noErr) {
  311.         OutOfMemory(1010);
  312.         DisposeHandle((Handle)(**Params).terminal);
  313.         DisposeHandle((Handle)(**Params).session);
  314.         DisposeHandle((Handle)Params);
  315.         TelInfo->numwindows--;
  316.         updateCursor(1);
  317.         return(FALSE);
  318.         }
  319.         
  320.     DoTheMenuChecks();
  321.     
  322.       screens[cur].authenticate = SessPtr->authenticate && authOK;
  323.       screens[cur].encrypt = SessPtr->encrypt && encryptOK;
  324.  
  325. #ifdef newauth                            /* (RW) */
  326.     screens[cur].aedata = NULL;
  327. #else
  328.      if (screens[cur].authenticate || screens[cur].encrypt) {
  329.          if (screens[cur].edata = (CDATA *)NewPtrClear(sizeof(CDATA))) {
  330.              encrypt_init(screens[cur].edata, "Telnet", 0);
  331.              screens[cur].edata->wp = &screens[cur];
  332.          } else {
  333.              screens[cur].encrypt = false;
  334.              screens[cur].authenticate = false;
  335.              screens[cur].edata = NULL;
  336.          }
  337.      } else
  338.          screens[cur].edata = NULL;
  339. #endif
  340.      
  341.      for (scratchshort = 0; scratchshort < sizeof(screens[cur].myopts); scratchshort++) {
  342.         screens[cur].myopts[scratchshort] = 0;
  343.         screens[cur].hisopts[scratchshort] = 0;        
  344.     }    
  345.     screens[cur].cannon[0] = '\0';
  346.  
  347.     screens[cur].vtemulation = TermPtr->vtemulation;
  348.     screens[cur].forcesave = SessPtr->forcesave;
  349.     screens[cur].lineAllow = SessPtr->linemode;
  350.     screens[cur].eightbit = TermPtr->eightbit;    // Is this necessary?
  351.     screens[cur].portNum = SessPtr->port;
  352.     screens[cur].emacsmeta = TermPtr->emacsmetakey;
  353.     screens[cur].Xterm = TermPtr->Xtermsequences;
  354.     
  355.     screens[cur].port = -1;                // netxopen will take care of this
  356.  
  357.     screens[cur].lmode = 0;
  358.     for (scratchshort=0; scratchshort<= SLC_ARRAY_SIZE; scratchshort++)
  359.         screens[cur].slc[scratchshort] = -1;
  360.     screens[cur].slc[SLC_IP] = 3;
  361.     screens[cur].slc[SLC_EC] = 127;
  362.     screens[cur].slc[SLC_EL] = 21;
  363.     screens[cur].slc[SLC_EOF] = 4;
  364.     screens[cur].slc[SLC_ABORT] = 3;
  365.     screens[cur].slc[SLC_SUSP] = 26; 
  366.  
  367.     // If the caller has not specified a window location, come up with our own.
  368.     // This function can possibly stagger windows right off the screen.
  369.     if((**Params).WindowLocation.top == 0) {
  370.         offset = ((gApplicationPrefs->StaggerWindows == TRUE) ? 10 : 2) * (stagNum++);
  371.         (**Params).WindowLocation.top = GetMBarHeight() + 10 + offset;
  372.         (**Params).WindowLocation.left  = offset;
  373.         (**Params).WindowLocation.bottom= 30000 + offset;
  374.         (**Params).WindowLocation.right = 30000 + offset;
  375.         }
  376.         
  377.     GetFNum(TermPtr->DisplayFont, &fontnumber);
  378.     
  379.     screens[cur].vs = RSnewwindow( &((**Params).WindowLocation), TermPtr->numbkscroll, TermPtr->vtwidth,
  380.                                     TermPtr->vtheight, (**Params).WindowName, TermPtr->vtwrap,
  381.                                     fontnumber, TermPtr->fontsize, 0,
  382.                                     1,
  383.                                     SessPtr->forcesave);
  384.                                     
  385.     if (screens[cur].vs <0 ) {     /* we have a problem opening up the virtual screen */
  386.         OutOfMemory(1011);
  387.         DisposeHandle((Handle)(**Params).terminal);
  388.         DisposeHandle((Handle)(**Params).session);
  389.         DisposeHandle((Handle)Params);
  390.         TelInfo->numwindows--;
  391.         DoTheMenuChecks();
  392.         updateCursor(1);
  393.         return(FALSE);
  394.         }
  395.  
  396.     screens[cur].wind = RSgetwindow( screens[cur].vs);
  397.     ((WindowPeek)screens[cur].wind)->windowKind = WIN_CNXN;
  398.     
  399.     /*
  400.      * Attach our extra part to display encryption status
  401.      */
  402.     PatchWindowWDEF(screens[cur].wind, &screens[cur]);
  403.  
  404.     screens[cur].arrowmap = TermPtr->emacsarrows;          /* MAT -- save our arrow setting */
  405.     screens[cur].maxscroll= TermPtr->numbkscroll;
  406.     screens[cur].rows = TermPtr->vtheight;                /* BYU 2.4.16 */
  407.     screens[cur].bsdel = SessPtr->bksp;
  408.     screens[cur].crmap = SessPtr->crmap;
  409.     screens[cur].tekclear = SessPtr->tekclear;
  410.     screens[cur].ESscroll= TermPtr->clearsave;
  411.     screens[cur].tektype = SessPtr->tektype;
  412.     screens[cur].wrap = TermPtr->vtwrap;
  413.     screens[cur].pgupdwn = TermPtr->MATmappings;        /* JMB: map pgup/pgdwn/home/end? */
  414.     screens[cur].width= TermPtr->vtwidth;
  415.     screens[cur].TELstop = SessPtr->skey;
  416.     screens[cur].TELgo = SessPtr->qkey;
  417.     screens[cur].TELip = SessPtr->ckey;
  418.     BlockMove((Ptr)SessPtr->hostname, screens[cur].machine, Length(SessPtr->hostname)+1);
  419.     BlockMove(TermPtr->AnswerBackMessage, screens[cur].answerback, 32);
  420.     screens[cur].termstate = VTEKTYPE;
  421.     screens[cur].naws = 0;                                /* NCSA - set default NAWS to zero */
  422.     screens[cur].xfer=0;
  423.     screens[cur].telstate=0;
  424.     screens[cur].timing=0;
  425.     screens[cur].curgraph=-1;                /* No graphics screen */
  426.     screens[cur].ftpport = -1;                /* BYU - No additional FTP port opened yet */
  427.     screens[cur].clientflags = 0;            /* BYU */
  428.     screens[cur].kblen = 0;                /* nothing in the buffer */
  429.     screens[cur].enabled = 1;            /* Gotta be enabled to start with */
  430.     screens[cur].Ittype = 0;
  431.     screens[cur].Isga = 0;                /* I suppress go ahead = no */
  432.     screens[cur].Usga = 0;                /* U suppress go ahead = no */
  433.  
  434.     screens[cur].ftpstate = (**Params).ftpstate;    /* BYU */
  435.     if ((**Params).ftpstate != 0) {        /* BYU */
  436.         screens[cur].termstate=DUMBTYPE;    /* BYU */
  437.         screens[cur].echo=1;                /* BYU - Echo for ftp */
  438.         screens[cur].halfdup = 1;            /* BYU */
  439.     } else {                            /* BYU */
  440.         screens[cur].termstate=VTEKTYPE;    /* BYU */
  441.         screens[cur].echo = 1;
  442.         screens[cur].halfdup = SessPtr->halfdup;    /* BYU */
  443.     }
  444.     
  445.     screens[cur].national = 0;            // Default to no translation.
  446.     // Now see if the desired translation is available, if not use default translation.
  447.     for(scratchshort = 1; scratchshort <= nNational+1; scratchshort++) {
  448.         GetItem(myMenus[National], scratchshort, scratchPstring);
  449.         if (EqualString(SessPtr->TranslationTable, scratchPstring, TRUE, FALSE))
  450.             screens[cur].national = scratchshort-1;
  451.         }
  452.                 
  453.     
  454.     // Set up paste related variables
  455.     screens[cur].incount = 0;
  456.     screens[cur].outcount = 0;
  457.     screens[cur].outptr = NULL;
  458.     screens[cur].outhand = NULL;
  459.     screens[cur].outlen = 0;
  460.     screens[cur].pastemethod = SessPtr->pastemethod;
  461.     screens[cur].pastesize = SessPtr->pasteblocksize;
  462.     
  463.     scratchBoolean = NewRSsetcolor( screens[cur].vs, 0, TermPtr->nfcolor);
  464.     scratchBoolean = NewRSsetcolor( screens[cur].vs, 1, TermPtr->nbcolor);
  465.     scratchBoolean = NewRSsetcolor( screens[cur].vs, 2, TermPtr->bfcolor);
  466.     scratchBoolean = NewRSsetcolor( screens[cur].vs, 3, TermPtr->bbcolor);
  467.  
  468.     addinmenu(cur, (**Params).WindowName, diamondMark);
  469.     screens[cur].active = CNXN_DNRWAIT;            // Signal we are waiting for DNR.
  470.  
  471.     screens[cur].myInitParams = (Handle)Params;
  472.     HUnlock((Handle)(**Params).terminal);
  473.     HUnlock((Handle)(**Params).session);
  474.     // Params handle must stay locked because interrupt level DNR completion routine needs to deref it
  475.  
  476.     VSscrolcontrol( screens[cur].vs, -1, screens[cur].ESscroll);
  477.  
  478.     updateCursor(1);                            /* Done stalling the user */
  479.     return(TRUE);
  480. }
  481.  
  482. void    CompleteConnectionOpening(short dat, ip_addr the_IP, OSErr DNRerror, char *cname)
  483. {
  484.     ConnInitParams    **Params;
  485.     
  486.     if (screens[dat].active != CNXN_DNRWAIT) return;            // Something is wrong.
  487.     
  488.     Params = (ConnInitParams **)screens[dat].myInitParams;
  489.     
  490.     if (DNRerror == noErr) {
  491.         HLockHi((Handle)(**Params).session);
  492.         if (screens[dat].ftpstate != 0)                 /* BYU - ftp client */
  493.             screens[dat].port  = netxopen(the_IP,HFTP,40);    /* BYU 2.4.15 - open to host name */
  494.         else                                             /* BYU */
  495.             screens[dat].port  = netxopen(the_IP,(**(**Params).session).port,40);/* BYU 2.4.15 - open to host name */
  496.         
  497.         // We need the cannonical hostname for Kerberos. Make best guess if
  498.         // DNR did not return a cname.
  499.         if (cname)
  500.             strncpy(screens[dat].cannon, cname, sizeof(screens[dat].cannon));
  501.         else
  502.             strncpy(screens[dat].cannon, (char *)(**(**Params).session).hostname, sizeof(screens[dat].cannon));
  503.         screens[dat].cannon[sizeof(screens[dat].cannon)-1] = '\0';
  504.         
  505.         DisposeHandle((Handle)(**Params).session);
  506.         DisposeHandle((Handle)(**Params).terminal);
  507.         DisposeHandle((Handle)Params);
  508.         
  509.         if (screens[dat].port <0) {                    /* Handle netxopen fail */
  510.             destroyport(dat);
  511.             }
  512.         screens[dat].active = CNXN_OPENING;
  513.         SetMenuMarkToOpeningForAGivenScreen(dat);    /* Change status mark */
  514.         }
  515.     else
  516.         {    // We should report the real DNR error here!
  517.         Str255        errorString, numberString, numberString2, scratchPstring;
  518.         DialogPtr    theDialog;
  519.         short        message, ditem = 3;
  520.         
  521.         HLockHi((Handle)(**Params).session);
  522.         BlockMove((**(**Params).session).hostname, scratchPstring, Length((**(**Params).session).hostname)+1);
  523.  
  524.         if (DNRerror >= -23048 && DNRerror <= -23041) message = DNRerror + 23050;
  525.         else message = 1;
  526.         
  527.         GetIndString(errorString,DNR_MESSAGES_ID, message);
  528.         NumToString((long)0, numberString);
  529.         NumToString((long)DNRerror, numberString2);
  530.         ParamText(scratchPstring, errorString, numberString, numberString2);
  531.         
  532.         theDialog = GetNewMyDialog(DNRErrorDLOG, NULL, kInFront, (void *)ThirdCenterDialog);
  533.         ShowWindow(theDialog);
  534.     
  535.         while (ditem > 1)    ModalDialog(DLOGwOKUPP, &ditem);
  536.         DisposeDialog(theDialog);
  537.  
  538.         DisposeHandle((Handle)(**Params).session);
  539.         DisposeHandle((Handle)(**Params).terminal);
  540.         DisposeHandle((Handle)Params);
  541.         destroyport(dat);
  542.         }
  543. }
  544.  
  545. void destroyport(short wind)
  546. {
  547.     Handle    h;
  548.     short    i,
  549.             callNoWindow=0;
  550.  
  551.     SetCursor(theCursors[watchcurs]);        /* We may be here a while */
  552.  
  553.     if (screens[wind].active == CNXN_ISCORPSE) {
  554.         if (screens[wind].curgraph>-1)
  555.             detachGraphics( screens[wind].curgraph);    /* Detach the Tek screen */
  556.         if (screens[wind].outlen>0) {
  557.             screens[wind].outlen=0;                        /* Kill the remaining send*/
  558.             HUnlock( screens[wind].outhand);            /*  buffer */
  559.             HPurge ( screens[wind].outhand);
  560.             }
  561.         }
  562.  
  563.     if (FrontWindow() == screens[wind].wind)
  564.         callNoWindow=1;
  565.  
  566. #ifdef newauth        // (RW)
  567.     if (screens[wind].aedata != NULL)
  568.         DisposePtr((Ptr)screens[wind].aedata);
  569. #else
  570.      if (screens[wind].edata != NULL)
  571.          DisposePtr((Ptr)screens[wind].edata);
  572. #endif
  573.  
  574.     /*
  575.      * Get handle to the WDEF patch block, kill the window, and then
  576.      * release the handle.
  577.      */
  578.     h = GetPatchStuffHandle(screens[wind].wind, &screens[wind]);
  579.     RSkillwindow( screens[wind].vs);
  580.     if (h)
  581.         DisposeHandle(h);
  582.  
  583.     screens[wind].active = CNXN_NOTINUSE;
  584.     for (i=wind;i<TelInfo->numwindows-1;i++) {
  585.         screens[i]=screens[i+1];        /* Bump all of the pointers */
  586.         RePatchWindowWDEF(screens[i].wind, &screens[i]);    /* hack hack hack */
  587. #ifndef newauth    // (RW)
  588.          if (screens[i].edata)
  589.              screens[i].edata->wp = &screens[i];
  590. #endif
  591.         }
  592.     if (scrn>wind) scrn--;                /* Adjust for deleting a lower #ered screen */
  593.  
  594.     TelInfo->numwindows--;                        /* There are now fewer windows */
  595.     extractmenu( wind);                    /* remove from the menu bar */
  596.  
  597.     DoTheMenuChecks();
  598.  
  599. /* BYU 2.4.11 - the call to "NoWindow()" changes "myfrontwindow", 
  600.                 which is used by "updateCursor()", so we reversed 
  601.                 the order of the following two lines. */
  602.     if (callNoWindow) NoWindow();        /* BYU 2.4.11 - Update cursor stuff if front window */
  603.     updateCursor(1);                    /* BYU 2.4.11 - Done stalling the user */
  604.  
  605. } /* destroyport */
  606.  
  607. void removeport(short n)
  608. {
  609.     Str255        scratchPstring;
  610.     
  611.     SetCursor(theCursors[watchcurs]);                /* We may be here a while */
  612.  
  613.     if (screens[n].curgraph>-1)
  614.         detachGraphics( screens[n].curgraph);        /* Detach the Tek screen */
  615.         
  616.     if (screens[n].outlen>0) {
  617.                 screens[n].outlen=0;                /* Kill the remaining send*/
  618.                 HUnlock( screens[n].outhand);        /*  buffer */
  619.                 HPurge ( screens[n].outhand);
  620.                 }
  621.  
  622.     if (VSiscapturing(screens[n].vs))                /* NCSA: close up the capture */
  623.         CloseCaptureFile(screens[n].vs);            /* NCSA */
  624.  
  625.     if (VSisprinting(screens[n].vs))
  626.         ClosePrintingFile(screens[n].vs);
  627.         
  628.     if (!gApplicationPrefs->WindowsDontGoAway)
  629.         destroyport(n);
  630.     else {
  631.         Str255    temp;
  632.         
  633.         GetWTitle(screens[n].wind, scratchPstring);
  634. #ifdef THINK_C
  635.         sprintf((char *)temp, "(%#s)", scratchPstring);
  636. #else
  637.         PtoCstr(scratchPstring);
  638.         sprintf((char *)temp, "(%s)", scratchPstring);
  639. #endif
  640.         CtoPstr((char *)temp);
  641.         SetWTitle(screens[n].wind, temp);
  642.  
  643.         screens[n].port = 32700;
  644.         screens[n].active = CNXN_ISCORPSE;
  645.         }
  646.  
  647.     updateCursor(1);                            /* Done stalling the user */
  648. } /* removeport */
  649.  
  650.  
  651.  
  652.